﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebsiteLab2.BUS
{
    public class ProductBUS
    {
        public static OurServices.Service1 ourservices;

        static ProductBUS ()  {
            ourservices = new OurServices.Service1 ();
        }

        public static object createObject(string value, string type){
            object result = null ;
            
            switch (type)
            {
                case "int": result = int.Parse(value); break;
                case "float": result = float.Parse(value); break;
                case "bool": result = bool.Parse(value); break;
                default: result = value; break;
            }

            return result;
        }

        public static List<OurServices.Product> getAllProductsByServices(){
            List<OurServices.Product> products = new List<OurServices.Product>();

            ourservices = (ourservices == null) ? ourservices = new OurServices.Service1() : ourservices;

            OurServices.Product[] productsTemp = ourservices.getAllProduct();

            if (productsTemp.Count() < 1) { return products; }

            foreach (OurServices.Product item in productsTemp)
            {
                products.Add(item);
            }

            return products;
        }

        public static List<OurServices.Product> getAllProductsByTypesServices(string typeID)
        {
            
            List<OurServices.Product> products = new List<OurServices.Product>();

            if (typeID == null || typeID == "") { return products; }

            ourservices = (ourservices == null) ? ourservices = new OurServices.Service1() : ourservices;

            OurServices.Product[] productsTemp = ourservices.getAllByType(typeID);

            if (productsTemp.Count() < 1) { return products; }

            foreach (OurServices.Product item in productsTemp)
            {
                products.Add(item);
            }

            return products;
        }

        public static List<String> getAllTypesByServices()
        {
            List<String> categories = new List<String>();

            ourservices = (ourservices == null) ? ourservices = new OurServices.Service1() : ourservices;

            String [] categoriesTemp = ourservices.getProductTypes();

            if (categoriesTemp.Count() < 1) { return categories; }

            foreach (String item in categoriesTemp)
            {
                categories.Add(item);
            }

            return categories;
        }
    }
}
